﻿#region

using System;
using Microsoft.Win32;

#endregion

namespace ChangeStartUp
{
	class Program
	{
		static void Main(string[] args)
		{
			string commandName = "";
			string command = "";
			string value = "";

			try
			{
				commandName = args[0];
				command = args[1];
				value = args[2];
			}
			catch (Exception)
			{
				string arguments = "";
				foreach (string thisArg in args)
				{
					arguments = thisArg + " ";
				}

				Console.WriteLine("Error in usage");
				Console.WriteLine("Usage: ChangeStartUp [commandName] [command] [value]");
				Console.WriteLine("commandName - Name for the application/registry key");
				Console.WriteLine("command - Full path to the executable");
				Console.WriteLine("value - enable|disable - Add or remove the key");
				Console.WriteLine("");
				Console.WriteLine("What you used: " + arguments);
				Console.WriteLine("Press any key to continue...");
				Console.ReadKey();
			}

			if ((command != "") && (commandName != "") && (value != ""))
			{
				RegistryKey runRegistry = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
				string runRegistryValue = (string)runRegistry.GetValue(commandName, "");

				Console.WriteLine(runRegistry.ValueCount.ToString());

				if ((value == "enable") && (runRegistryValue == ""))
				{
					runRegistry.SetValue(commandName, command);
				}
				else if ((value == "disable") && (runRegistryValue != ""))
				{
					runRegistry.DeleteValue(commandName);
				}
			}
		}
	}
}
